home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Loadstar 3
/
003.d81
/
base converter
(
.txt
)
< prev
next >
Wrap
Commodore BASIC
|
2022-08-26
|
2KB
|
94 lines
50 sp$=" "
60 foras=0to38:sp$=sp$+" ":next
90 print"[147]":poke53281,7:poke53280,6:poke783,peek(783)and254
100 poke781,2:poke782,11:sys65520:print" base conversion "
110 :
120 :
130 ifp=1then150
140 rem fork=0to2200:print;:next
150 n$="0123456789abcdefghijklmnopqrstuvwxyz"
160 poke781,6:poke782,0:sys65520
162 forcl=1to18:printsp$;:next
170 m=len(n$)
180 poke781,5:poke782,9:sys65520
190 print"use base ten notation"
200 poke781,8:poke782,0:sys65520
210 print"convert from"
220 print"base ";
230 input" [157][157][157][157][157][157]";b1$
240 ifb1$=chr$(.)then160
250 ifb1$="0"then160
260 rem test base number 1
270 b1=val(b1$)
280 ifb1>1 and b1<37 then320
290 poke781,22:poke782,1
300 sys65520:print"base 2 through 36 only. select again"
310 goto180
320 poke781,8:poke782,26:sys65520:
330 print"converted to"
340 poke781,10:sys65520:print"base ";
350 input" [157][157][157][157][157]";b2$
360 ifb2$="0"then160
370 ifb2$=""then160
380 rem test base number 2
390 b2=val(b2$)
400 ifb2>1 and b2<m then445
410 poke781,22:poke782,1:sys65520:print"base 2 through 36 only. select again"
430 goto320
445 rem input number
450 poke781,11:poke782,1:sys65520:forcl=1to13:printsp$;:next
460 poke781,12:poke782,0:sys65520:print"value in base"b1"to convert";
470 input" [157][157][157][157]";s$
475 rem test input
480 l=len(s$)
490 ifs$="0"ors$=""then450
500 fork=1tol:a$=mid$(s$,k,1)
510 ifa$="."thenpoke781,12:sys65520:print"whole numbers only":forj=1to30000:next:goto450
530 next
540 q=0
550 fork=1tol
560 forj=1tob1
570 ifmid$(s$,k,1)=mid$(n$,j,1)thenq=q+1
580 nextj,k
590 ifl>qthengosub980:goto450
600 rem first conver to base 10
610 y1=y1+1
620 poke781,19:poke782,10:sys65520:print"";mg$(y1)
640 ify1=10theny1=0
650 ifl<=7then670
660 poke781,23:poke782,2:sys65520:print"answer may be wrong, number too long[146]";
670 fork=1to500*l:nextk
675 rem the heart of the program
680 d=0
690 fork=1tol
700 forj=1tob1
710 ifmid$(n$,j,1)<>mid$(s$,k,1)then730
720 d=d+int(((j-1)*(b1^(l-k))+.5))
730 nextj,k
750 rem convert for output
760 a$=" "
770 x=int(((d/b2)-int(d/b2))*b2+1.5)
780 a$=mid$(n$,x,1)+a$
790 d=int(d/b2)
800 ifd>0then770
810 rem print results
820 poke781,15:poke782,0:sys65520:prints$;" ";:poke781,15:poke782,30:sys65520
825 print"base ";b1
830 printa$;" ":poke781,16:poke782,30:sys65520:print"base ";b2
840 print:poke781,18:poke782,0:sys65520
850 print"<return> to continue":print"<c> to change base":print"<x> to exit"
860 poke198,0:wait198,1:getq$:ifq$<>chr$(13) and q$<>"c" and q$<>"x"then860
870 if q$=chr$(13)then450
880 if q$="x"then920
890 p=1:goto90
910 stop rem the end
920 print"[147]load"chr$(34)"payload"chr$(34)",8":print"run":poke631,13:poke632,13
930 poke198,2:end
980 poke781,12:sys65520:forcl=1to6:printsp$;:next
990 poke783,peek(783)and254:poke781,12:poke782,12:sys65520:print"inproper input[146]"
1000 fork=1to2000:next:return
2000 rem written
2010 rem by
2020 rem bob scofield
2030 rem